package com.meixiang.activity.account.manager;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.lzy.okhttputils.model.HttpParams;
import com.meixiang.R;
import com.meixiang.global.Config;
import com.meixiang.http.HttpCallBack;
import com.meixiang.http.HttpUtils;
import com.meixiang.main.BaseActivity;
import com.meixiang.util.AbToastUtil;
import com.meixiang.view.CheckEditTextEmptyButton;

import org.json.JSONObject;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 编辑昵称
 * author：xiejingwen
 */
public class EditNickNameActivity extends BaseActivity {
    @Bind(R.id.edt_nick_name)
    EditText edtNickName;
    @Bind(R.id.btn_affirm)
    CheckEditTextEmptyButton btnAffirm;
   private  String MemberName;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_edit_nick_name);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initTitle() {
        setTitle(getResources().getString(R.string.edit_nick_name_title));
        if (!this.getIntent().getStringExtra("MemberName").equals("")){
             MemberName=this.getIntent().getStringExtra("MemberName");
            edtNickName.setText(MemberName);
        }

    }

    @Override
    protected void initView() {
        btnAffirm.setEditText(edtNickName);
    }


    @Override
    protected void setData() {

    }

    @Override
    @OnClick(R.id.btn_affirm)
    public void onClick(View v) {
        if (v.equals(btnAffirm)) {
            getEditNickName();
        }
    }

    private void getEditNickName() {
         if (edtNickName.getText().toString().length()<4){
             AbToastUtil.showToast(activity,"请输入4-20个字符组成，可由中英文、数字组成。");
             return;
         }
        HttpParams params = new HttpParams();
        params.put("nickName", edtNickName.getText().toString());

        HttpUtils.post(Config.SAVENICKNAME_URL, params, new HttpCallBack(EditNickNameActivity.this) {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                if (code.equals("0")) {
                    finish();
                }
            }

            @Override
            public void onError(String code, String message) {
                AbToastUtil.showToast(EditNickNameActivity.this, message);
            }
        });


    }


}
